home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / StreambufIterator.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  863 b   |  31 lines

  1. //: C20:StreambufIterator.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // istreambuf_iterator & ostreambuf_iterator
  7. #include "../require.h"
  8. #include <iostream>
  9. #include <fstream>
  10. #include <iterator>
  11. #include <algorithm>
  12. using namespace std;
  13.  
  14. int main() {
  15.   ifstream in("StreambufIterator.cpp");
  16.   assure(in, "StreambufIterator.cpp");
  17.   // Exact representation of stream:
  18.   istreambuf_iterator<char> isb(in), end;
  19.   ostreambuf_iterator<char> osb(cout);
  20.   while(isb != end)
  21.     *osb++ = *isb++; // Copy 'in' to cout
  22.   cout << endl;
  23.   ifstream in2("StreambufIterator.cpp");
  24.   // Strips white space:
  25.   istream_iterator<char> is(in2), end2;
  26.   ostream_iterator<char> os(cout);
  27.   while(is != end2)
  28.     *os++ = *is++;
  29.   cout << endl;
  30. } ///:~
  31.